#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX_SIZE 1000

int Tree[MAX_SIZE];
int CTree[MAX_SIZE];
void BuildComplete(int ALeft, int ARight, int TRoot);
int GetLeftLength(int n);
int compare(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}
int main()
{
    int N;
    
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &Tree[i]);
    }
    qsort(Tree, N, sizeof(int), compare);
    BuildComplete(0, N - 1, 0);
    printf("%d", CTree[0]);
    for (int i = 1; i < N; i++)
    {
        printf(" %d", CTree[i]);
    }
    return 0;
}
void BuildComplete(int ALeft, int ARight, int TRoot)
{
    int n = ARight - ALeft + 1;//现有总数
    if (n == 0)
        return;
    int L = GetLeftLength(n); //左子树个数
    CTree[TRoot] = Tree[ALeft + L];
    TRoot = TRoot * 2 + 1;
    BuildComplete(ALeft, ALeft + L - 1, TRoot);
    BuildComplete(ALeft + L + 1, ARight, TRoot + 1);
}
int GetLeftLength(int n)
{
    int H = floor(log2(n + 1));
    int X = (n + 1) - pow(2, H);
    return MIN(X, pow(2, H - 1)) + pow(2, H - 1) - 1;
}
